#coding:utf-8
from app import app

from flask.ext.sqlalchemy import SQLAlchemy

#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:123456@192.168.200.218:3306/xpdj'
db = SQLAlchemy(app)

class shop(db.Model):
    shop_id=db.Column(db.String(32),db.ForeignKey('shop_account.shop_id'),primary_key=True)
    shop_code=db.Column(db.String(32))
    shop_name=db.Column(db.String(128),nullable=False)
#    account=db.relationship('shop_account',backref=db.backref('account',lazy='dynamic'))

    def __init__(self, shop_id, shop_code, shop_name,account):
        self.shop_id = shop_id
        self.shop_code = shop_code
        self.shop_name= shop_name
 #       self.account=account

    def to_json(self):
        return{
            'shop_id':str(self.shop_id),
            'shop_code':str(self.shop_code),
            'shop_name':self.shop_name
        }

class shop_account(db.Model):
    __tablename__ = 'shop_account'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    shop_id=db.Column(db.String(32))
    account=db.Column(db.String(32))

    def __init__(self,id,shop_id,account):
        self.id=id
        self.shop_id=shop_id
        self.account=account
#select_=shop.query.filter_by(shop_name=u"嘿嘿2").first()
#select_=shop_account.query.join(shop,shop_account.shop_id==shop.shop_id).filter_by(shop_name=u"嘿嘿2").first()
#print select_.account

